<?php
	class InfoModel extends Model{
		public $page;				//分页的页号(当前页)
		public $evelpage=5;			//每页显示两条记录。
		public $pagenum;			//总共的页数。
		public $list;				//点评数据列表
		public $uid;				//用户ID(get)
	
		public function __construct($uid,$page,$type){
			$this->page=$page;
			$this->uid=$uid;
			$this->type=$type;
			$this->pagelist();
		}
		
		public function getcommentlist(){
			$sql='
				SELECT Id,ProjectId,ProjectName,Content,CreateUser,UserId,UserName,CreateDate 
				FROM projectcomment 
				WHERE UserId='.$this->uid.'
				order by CreateDate desc
			';
			$list=M()->query($sql);
			/* cache(array('type'=>'File','expire'=>3600));	//缓存设置
			cache('list1',$list); */						//缓存数据
			return $list;
		}
		
		public function getbloglist(){
			$sql='
				SELECT Id,Title,ViewCount,CreateDate,CreateUser,CommentCount,Content
				FROM bloglog
				WHERE CreateUser='.$this->uid.' and IsDeleted=0
				order by CreateDate desc
			';
			$list=M()->query($sql);
			/* cache(array('type'=>'File','expire'=>3600));	//缓存设置
			cache('list2',$list);	 */					//缓存数据
			return $list;
		}
		
		public function getresourcelist(){
			$sql='
				SELECT Id,Title,ViewCount,CreateDate,CreateUser,Content
				FROM studyresources
				WHERE CreateUser='.$this->uid.' and IsDeleted=0
				order by Createdate desc
			';
			$list=M()->query($sql);
			/* cache(array('type'=>'File','expire'=>3600));	//缓存设置
			cache('list3',$list);	 */					//缓存数据
			return $list;
		}
		
		public function pagelist(){
			$page = $this->page;		//当前页号
			switch($this->type){
				case 0:
					if(!($pinfo = cache('list1'))){				//读取缓存的数据
						$pinfo = $this->getcommentlist();
					}
				break;
				case 1:
					if(!($pinfo = cache('list2'))){				//读取缓存的数据
						$pinfo = $this->getbloglist();
					}
				break;
				case 2:
					if(!($pinfo = cache('list3'))){				//读取缓存的数据
						$pinfo = $this->getresourcelist();
					}
				break;
			}
			$count=count($pinfo);		//总记录数
			$page=($page<1)?1:(($page>ceil($count/$this->evelpage))?ceil($count/$this->evelpage):$page);
			$t=(($page-1)*($this->evelpage));
			for($i=0;$i<($this->evelpage);$i++){
				if($pinfo[$t+$i])
					$log[$i]=$pinfo[$t+$i];
			}
			$this->list = $log;
			$this->pagenum = ceil($count/$this->evelpage);
		}
		
	}
?>